package com.x.client.bean

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName


/**
 *  Creator : GG
 *  Time    : 2017/12/1
 *  Mail    : gg.jin.yu@gmail.com
 *  Explain :
 */

data class City(
        @SerializedName("cityCode") var cityCode: String? = "", //000100010001
        @SerializedName("cityId") var cityId: String? = "", //110100
        @SerializedName("cityInitial") var cityInitial: String? = "", //BJS
        @SerializedName("cityName") var cityName: String? = "", //北京市
        @SerializedName("cityPinyin") var cityPinyin: String? = "", //beijingshi
        @SerializedName("citySeq") var citySeq: Int? = 0, //0
        @SerializedName("cityState") var cityState: Int? = 0, //1
        @SerializedName("province") var province: Province? = Province(),
        @SerializedName("provinceId") var provinceId: String? = "",//110000
        var status: Boolean = false
) : Parcelable {
    override fun equals(other: Any?): Boolean {
        val item = other as City
        return cityId == item.cityId
    }

    override fun hashCode(): Int {
        return cityId?.hashCode() ?: 0
    }

    constructor(source: Parcel) : this(
            source.readString(),
            source.readString(),
            source.readString(),
            source.readString(),
            source.readString(),
            source.readValue(Int::class.java.classLoader) as Int?,
            source.readValue(Int::class.java.classLoader) as Int?,
            source.readParcelable<Province>(Province::class.java.classLoader),
            source.readString(),
            1 == source.readInt()
    )

    override fun describeContents() = 0

    override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
        writeString(cityCode)
        writeString(cityId)
        writeString(cityInitial)
        writeString(cityName)
        writeString(cityPinyin)
        writeValue(citySeq)
        writeValue(cityState)
        writeParcelable(province, 0)
        writeString(provinceId)
        writeInt((if (status) 1 else 0))
    }

    companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<City> = object : Parcelable.Creator<City> {
            override fun createFromParcel(source: Parcel): City = City(source)
            override fun newArray(size: Int): Array<City?> = arrayOfNulls(size)
        }
    }
}
